package vaani.internal.purple;

import java.util.Vector;

/**
 *
 * @author sourcemorph
 */

public class BuddyLocator {
    /*class containing independent logic of searching through buddy list, again the approach will be
     * to have multiple passes, and with each subsequent pass, relaxing the search criterion*/
    private static Vector<Result> queryResult;

    public static Vector<Result> makeQuery(Vector<String> arguments) {
        /*pass one: with all arguments*/
        queryResult = BuddyListHandler.findBuddies(arguments);
        if(queryResult.size() != 0) {
            return queryResult;
        }
        /*pass two, maybe one of the arguments was the protocol name, consider that and retry*/
        for(String s : arguments) {
            if(BuddyListHandler.matchProtocol(s)) {
                Vector<String> tempQuery = (Vector<String>)arguments.clone();
                tempQuery.remove(s);
                queryResult = BuddyListHandler.findBuddies(tempQuery);
                if(queryResult.size() != 0) {
                    return queryResult;
                }
            }
        }
        return null;
    }
}
